package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.web.bind.annotation.ModelAttribute;

import cn.itcast.crm.domain.Customer;

public interface CustomerRepository extends JpaRepository<Customer, Integer>{
	
	public List<Customer> findByFixedAreaIdIsNull();

	public List<Customer> findByFixedAreaId(String fixedAreaId);

	@Query("update Customer set fixedAreaId = null where fixedAreaId = ?")
	@Modifying
	public void clearFixedAreaId(String fixedAreaId);

	@Query("update Customer set fixedAreaId = ? where id = ?")
	@Modifying
	public void updateFixedAreaId(String fixedAreaId, int customerId);

	public Customer findByTelephone(String telephone);

	@Query("update Customer set type=1 where telephone = ?")
	@Modifying
	public void updateType(String telephone);

	//用户登陆
	public Customer findByTelephoneAndPassword(String telephone, String password);

	//通过客户ID和寄件人地址获取定区ID
	@Query("select fixedAreaId from Customer where id=?2 and address=?1")
	public String findFixAreaIdByAddressAndID(String sendAddress, Integer customerId);


}
